var WeekLabel = ["07-01", "07-02", "07-03", "07-04", "07-05", "07-06", "07-07"];
var WeekDataOrder = [3,4,6,4,5,9,2];
var WeekDataTurnover = [345.25,499.50,750.00,285.60,375.00,1200.00,250.50];
var WeekDataMember = [8,15,32,28,19,42,5];

var MonthLabel = ["07-01", "07-02", "07-03", "07-04", "07-05", "07-06", "07-07","07-08", "07-09", "07-10", "07-11", "07-12", "07-13", "07-14","07-15", "07-16", "07-17", "07-18", "07-19", "07-20", "07-21","07-22", "07-23", "07-24", "07-25", "07-26", "07-27", "07-28","07-29","07-30","07-31"];
var MonthDataOrder = [3,4,6,4,5,9,2,3,4,6,4,5,9,2,3,4,6,4,5,9,2,3,4,6,4,5,9,2,3,7,7];
var MonthDataTurnover = [345.25,499.50,750.00,285.60,375.00,1200.00,250.50,345.25,499.50,750.00,285.60,375.00,1200.00,250.50,345.25,499.50,750.00,285.60,375.00,1200.00,250.50,345.25,499.50,750.00,285.60,375.00,1200.00,250.50,256.30,456,50,260.00];
var MonthDataMember = [8,15,32,28,19,42,5,8,15,32,28,19,42,5,8,15,32,28,19,42,5,8,15,32,28,19,42,5,45,75,23];

var lineChartData = {
  labels: WeekLabel,
  datasets: [{
    label: '订单数',
    borderColor: 'rgb(68, 181, 73)',
    backgroundColor: 'rgba(68, 181, 73,0.1)',
    pointBorderColor: 'rgb(68, 181, 73)',
    data: WeekDataOrder
  }, {
    label: '营业额',
    borderColor: 'rgb(94, 169, 248)',
    backgroundColor: 'rgba(94, 169, 248,0.1)',
    pointBorderColor: 'rgb(94, 169, 248)',
    data: WeekDataTurnover
  }, {
    label: '新增会员数量',
    borderColor: 'rgb(255, 66, 0)',
    backgroundColor: 'rgba(255, 66, 0,0.1)',
    pointBorderColor: 'rgb(255, 66, 0)',
    data: WeekDataMember
  }]
};
$.each(lineChartData.datasets, function(i, dataset) {
  dataset.borderWidth = 2;
  dataset.pointBackgroundColor = 'rgb(255, 255, 255)';
  dataset.pointBorderWidth = 2;
});
window.onload = function() {
  var ctx = document.getElementById("datachart").getContext("2d");
  window.myLine = new Chart(ctx, {
    type: 'line',
    data: lineChartData,
    options: {
      responsive: true,
      legend: {
        position: 'top',
      },
      title: {
        display: true,
        text: 'CM微店关键指标增长趋势'
      }
    }
  });
};
$('#week').click(function() {
  lineChartData.labels = WeekLabel;
  lineChartData.datasets[0].data = WeekDataOrder;
  lineChartData.datasets[1].data = WeekDataTurnover;
  lineChartData.datasets[2].data = WeekDataMember;
  window.myLine.update();
});
$('#month').click(function() {
  lineChartData.labels = MonthLabel;
  lineChartData.datasets[0].data = MonthDataOrder;
  lineChartData.datasets[1].data = MonthDataTurnover;
  lineChartData.datasets[2].data = MonthDataMember;
  window.myLine.update();
});
$(function() {
  $(".shop-edit").click(function(event) {
    $(this).parents(".list-group-item").find(".shop-text").hide();
    $(this).parents(".list-group-item").find(".shop-input").show();
    $(this).parents(".list-group-item").find(".shop-input").focus();
    $(this).parents(".list-group-item").find(".shop-sure").show();
    $(this).hide();
  });
  $(".shop-sure").click(function(event) {
    $(this).parents(".list-group-item").find(".shop-input").hide();
    $(this).parents(".list-group-item").find(".shop-text").show();
    $(this).parents(".list-group-item").find(".shop-edit").show();
    $(this).hide();
  });

  //switch
  $(".switch").click(function(event) {
    if($(this).hasClass("switch-off")){
      $(this).addClass("switch-on");
      $(this).removeClass("switch-off");
    }
    else if($(this).hasClass("switch-on")){
      $(this).addClass("switch-off");
      $(this).removeClass("switch-on");
    }
  });

  //.search
  $(".search-box input[type='search']").keyup(function(event) {
    var length = $(this).val().length;
    if(length > 0){
      $(this).siblings('.search-text-clear').removeClass('hidden');
    }
    else if(length == 0){
      $(this).siblings('.search-text-clear').addClass('hidden');
    }
  });
  $(".search-text-clear").click(function(event) {
    $(this).siblings("input[type='search']").val("");
    $(this).addClass('hidden');
  });

  //chart
  $(".data-chart-btns button").click(function(event) {
    $(".data-chart-btns button").removeClass("active");
    $(this).addClass("active");
  });
  //check all
  $(".checkall").click(function(event) {
    if(this.checked) {
      $(".table-cmcm input:checkbox").each(function(index, el) {
        $(this).prop('checked', true);
      });
    }
    else{
      $(".table-cmcm input:checkbox").each(function(index, el) {
        $(this).prop('checked', false);
      });
    }
  });

  //tabs-box
  $(".tabs-box li").click(function(event) {
    $(this).parent(".tabs-box").find("li").removeClass("active");
    $(this).addClass("active");
    var target = $(this).attr('data-target');
    $(target).parent(".tabs-con").find(".tabs-item").removeClass("active");
    $(target).addClass("active");
  });
  // goods-num
  $(".goods-num .plus").click(function(event) {
    var num = $(this).siblings(".num").text();
    if(num>=1){
      num++;
      $(this).siblings(".num").text(num);
    }
  });
  $(".goods-num .minus").click(function(event) {
    var num = $(this).siblings(".num").text();
    if(num>1){
      num--;
      $(this).siblings(".num").text(num);
    }
  });


  //datetimepicker
  $('#datetime-start').datetimepicker({
    format: 'YYYY-MM-DD HH:mm:ss'
  });
  $('#datetime-end').datetimepicker({
    format: 'YYYY-MM-DD HH:mm:ss'
  });
  $("#datetime-start").on("dp.change", function (e) {
    $('#datetime-end').data("DateTimePicker").minDate(e.date);
  });
  $("#datetime-end").on("dp.change", function (e) {
    $('#datetime-start').data("DateTimePicker").maxDate(e.date);
  });

});
